package cn.tedu.charging.user.controller;

import cn.tedu.charging.common.pojo.param.ChargeParam;
import cn.tedu.charging.common.pojo.param.VehicleBindParam;
import cn.tedu.charging.common.pojo.vo.BalanceVO;
import cn.tedu.charging.common.pojo.vo.VehicleVO;
import cn.tedu.charging.common.protocol.JsonResult;
import cn.tedu.charging.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.elasticsearch.search.DocValueFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@Slf4j
@RestController
public class UserController {
    @Autowired
    private UserService userService;

//    微信小程序微信登录
    @GetMapping("/user/wx/login")
    public JsonResult<Integer> wxLogin(String nickname,String code){
//       调用业务层， 获取当前用户
        Integer uid = userService.wxLogin(nickname,code);
        return JsonResult.ok(uid);
    }
    @GetMapping("/user/balance/{userId}")
    public JsonResult<BalanceVO > getBalance(@PathVariable Integer userId){
        log.debug("获取用户余额"+userId);
        BalanceVO  balanceVO = userService.getBalance(userId);
        return JsonResult.ok(balanceVO);
    }
    @PostMapping("/user/charge/")
    public JsonResult<Void> charge(@RequestBody ChargeParam chargeParam){
        log.debug("充值"+chargeParam);
        userService.charge(chargeParam);
        return JsonResult.ok(null);
    }
    @GetMapping("/user/vehicle/binded/{userId}")
    public JsonResult<VehicleVO> getVehicle(@PathVariable Integer userId){
        log.debug("获取用户车辆"+userId);
        VehicleVO vehicleVO = userService.getVehicle(userId);
        return JsonResult.ok(vehicleVO);
    }
    @PostMapping("/user/vehicle/bind")
    public JsonResult<Void> bindVehicle(@RequestBody VehicleBindParam vehicleBindParam){
        log.debug("绑定车辆"+vehicleBindParam);
        userService.bindVehicle(vehicleBindParam);
        return JsonResult.ok(null);
    }
}
